package com.example.algebratest;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;

public class QuestioniiiActivity extends Activity {
	
	Button button, button1, button2, button3;
	
	Bluetooth b = new Bluetooth();
	TimedResponse tr;
	long qStart;
	public final static int DIFFICULTY = 0;
	
	/** Called when the user clicks the Send button */
	public void next(View view) {
		long timeNow = System.currentTimeMillis();
		long timeSpent = timeNow-qStart;
		if(timeSpent<=30000){
			if (button2.isSelected()) { //change this to whatever the correct answer is
			    b.callComm("2");
			    }
		    else{
		    	b.callComm("5");
		    }
		} else if (timeSpent > 30000 && timeSpent < 90000){
			if (button2.isSelected()) { //change this to whatever the correct answer is
			    b.callComm("4");
			    }
		    else{
		    	b.callComm("7");
		    }
		} else {
			if (button2.isSelected()) { //change this to whatever the correct answer is
			    b.callComm("3");
			    }
		    else{
		    	b.callComm("6");
		    }
		}
	    tr.interruptTimer();
		
		Intent intent = new Intent(QuestioniiiActivity.this, QuestionivActivity.class);	    
	    startActivity(intent);
	}
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_questioniii);

  		tr = new TimedResponse(DIFFICULTY, b);
  		qStart = System.currentTimeMillis();
       
        button = (Button) findViewById(R.id.answerA);
        button1 = (Button) findViewById(R.id.answerB);
        button2 = (Button) findViewById(R.id.answerC);
        button3 = (Button) findViewById(R.id.answerD);
 //   final Button back = (Button) findViewById(R.id.back);
    /*final Button button = (Button) findViewById(R.id.answerA);
    final Button button1 = (Button) findViewById(R.id.answerB);
    final Button button2 = (Button) findViewById(R.id.answerC);
    final Button button3 = (Button) findViewById(R.id.answerD);
    */
 
    /*back.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
        	QuestioniiiActivity.this.onBackPressed();
        }
     });*/
    
        
        
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
        	if (button.isSelected()){
        		button.setSelected(false); 
        		
        				
        	} else {
  	            button.setSelected(true);
  	          button1.setSelected(false); 
      		button2.setSelected(false);
      		button3.setSelected(false);
      		b.callComm("1");
  	            //...Handled toggle on
  	        }
        	tr.interruptTimer();
        	tr = new TimedResponse(DIFFICULTY,b);
         }
        
        
     });
        	
	          
    //final Button button1 = (Button) findViewById(R.id.answerB);
    button1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
        	if (button1.isSelected()){
        		button1.setSelected(false); 
        				
        	} else {
  	            button1.setSelected(true);
  	          button.setSelected(false); 
      		button2.setSelected(false);
      		button3.setSelected(false);
      		b.callComm("1");
  	            //...Handled toggle on
  	        }
        	tr.interruptTimer();
        	tr = new TimedResponse(DIFFICULTY,b);
         }
        
        
     });
        
    //final Button button2 = (Button) findViewById(R.id.answerC);
    button2.setOnClickListener(new View.OnClickListener() {
    	 public void onClick(View v) {
         	if (button2.isSelected()){
         		button2.setSelected(false); 
         				
         	} else {
   	            button2.setSelected(true);
   	          button1.setSelected(false); 
       		button.setSelected(false);
       		button3.setSelected(false);
       		b.callComm("1");
   	            //...Handled toggle on
   	        }
         	tr.interruptTimer();
        	tr = new TimedResponse(DIFFICULTY,b);
          }
         
         
      });
    //final Button button3 = (Button) findViewById(R.id.answerD);
    button3.setOnClickListener(new View.OnClickListener() {
    	 public void onClick(View v) {
         	if (button3.isSelected()){
         		button3.setSelected(false); 
         				
         	} else {
   	            button3.setSelected(true);
   	          button1.setSelected(false); 
       		button2.setSelected(false);
       		button.setSelected(false);
       		b.callComm("1");
   	            //...Handled toggle on
   	        }
         	tr.interruptTimer();
        	tr = new TimedResponse(DIFFICULTY,b);
          }
         
         
      });
}
}

/* @Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.question1, menu);
    return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true;
    }
    return super.onOptionsItemSelected(item);
}*/


